<template>
    <div class="home-panel">
        <button class="changeBtn" @click="changeLoading()">
            <el-icon :class="{ 'is-loading': loading }"
                ><RefreshRight /></el-icon
            >换一换
        </button>
        <el-card class="box-card" shadow="hover">
            <!-- 头部标题 -->
            <template #header>
                <div class="card-header">
                    <span v-if="panelName">{{ panelName }}</span>
                    <template v-else>
                        <skeleton
                            width="60px"
                            height="18px"
                            style="margin-left: 5px"
                        ></skeleton>
                    </template>
                </div>
            </template>
            <el-scrollbar>
                <div class="card-body">
                    <template v-if="GoodsList && GoodsList.length">
                        <div
                            v-for="goods in GoodsList"
                            :key="Math.random().toString()"
                        >
                            <GoodsItem :goods="goods" />
                        </div>
                    </template>
                </div>
            </el-scrollbar>
        </el-card>
    </div>
</template>

<script setup>
import { ref } from 'vue'
defineProps({
    GoodsList: {},
    panelName: {},
    panelHeight: {
        default: 'auto',
    },
    panelDisplay: {
        default: 'black',
    },
})
const emits = defineEmits(['updateList'])
const loading = ref(false)
const changeLoading = () => {
    loading.value = true
    let timer = null
    setTimeout(() => {
        loading.value = false
        clearInterval(timer)
    }, 2000)
    emits('updateList')
}
</script>

<style lang="scss" scoped>
.home-panel {
    position: relative;
    width: 1200px;
    margin-top: 20px;
}
.card-header {
    > span {
        font-size: 18px;
    }
}
.card-body {
    height: v-bind(panelHeight);
    display: flex;
    flex-direction: row;
    align-items: center;
}
.changeBtn {
    width: 30px;
    height: 70px;
    border: none;
    border-radius: 5px;
    position: absolute;
    color: rgb(24, 25, 28);
    text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.4);
    font-size: 12px;
    text-align: center;
    cursor: pointer;
    display: v-bind(panelDisplay);
    transition: all 0.3s ease;
    right: -30px;
    &:hover {
        background-color: rgb(227, 229, 231);
    }
}
</style>
